<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 流年 <liu21st@gmail.com>
// +----------------------------------------------------------------------

// 应用公共文件
function isMobile()
{
    if (isset($_SERVER['HTTP_X_WAP_PROFILE'])) {
        return true;
    }
    if (isset($_SERVER['HTTP_VIA'])) {
        return stristr($_SERVER['HTTP_VIA'], "wap") ? true : false;
    }
    if (isset($_SERVER['HTTP_USER_AGENT'])) {
        $clientkeywords = array('nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap', 'mobile');
        if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))) {
            return true;
        }
    }
    if (isset($_SERVER['HTTP_ACCEPT'])) {
        if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== false) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === false || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))) {
            return true;
        }
    }
    return false;
}

/**
 * 子元素计数器
 * @param array $array
 * @param int $pid
 * @return array
 */
function array_children_count($array, $pid)
{
    $counter = [];
    foreach ($array as $item) {
        $count = isset($counter[$item[$pid]]) ? $counter[$item[$pid]] : 0;
        $count++;
        $counter[$item[$pid]] = $count;
    }
    return $counter;
}

/**
 * 数组层级缩进转换
 * @param array $array 源数组
 * @param int $pid
 * @param int $level
 * @return array
 */
function array2level($array, $pid = 0, $level = 1)
{
    static $list = [];
    foreach ($array as $v) {
        if ($v['pid'] == $pid) {
            $v['level'] = $level;
            $list[] = $v;
            array2level($array, $v['id'], $level + 1);
        }
    }
    return $list;
}

/**
 * 构建层级（树状）数组
 * @param array $array 要进行处理的一维数组，经过该函数处理后，该数组自动转为树状数组
 * @param string $pid_name 父级ID的字段名
 * @param string $child_key_name 子元素键名
 * @return array|bool
 */
function array2tree(&$array, $pid_name = 'pid', $child_key_name = 'children')
{
    $counter = array_children_count($array, $pid_name);
    if (!isset($counter[0]) || $counter[0] == 0) {
        return $array;
    }

    $tree = [];
    while (isset($counter[0]) && $counter[0] > 0) {
        $temp = array_shift($array);
        if (isset($counter[$temp['id']]) && $counter[$temp['id']] > 0) {
            array_push($array, $temp);
        } else {
            if ($temp[$pid_name] == 0) {
                $tree[] = $temp;
            } else {
                $array = array_child_append($array, $temp[$pid_name], $temp, $child_key_name);
            }
        }
        $counter = array_children_count($array, $pid_name);
    }
    return $tree;
}

/**
 * 把元素插入到对应的父元素$child_key_name字段
 * @param        $parent
 * @param        $pid
 * @param        $child
 * @param string $child_key_name 子元素键名
 * @return mixed
 */
function array_child_append($parent, $pid, $child, $child_key_name)
{
    foreach ($parent as &$item) {
        if ($item['id'] == $pid) {
            if (!isset($item[$child_key_name])) {
                $item[$child_key_name] = [];
            }

            $item[$child_key_name][] = $child;
        }
    }
    return $parent;
}

//获取无限级数组  $a数组中必须包含id,pid,name 3个字段
function get_tree_arr2($a, $id)
{
    $tree = array();                                //每次都声明一个新数组用来放子元素
    foreach ($a as $k => $v) {
        if ($v['pid'] == $id) {
            $children = get_tree_arr2($a, $v['id']); //递归获取子记录
            if ($children != null) {
                $v['children'] = 1; //是否有子节点
                $v['children_num'] = count($children);
                $tree[] = $v;
                $tree = array_merge($tree, $children);
            } else {
                $v['children'] = 0;
                $v['children_num'] = 0;
                $tree[] = $v;
            }
            unset($a[$k]);
        }
    }
    return $tree;                                  //返回新数组
}

function get_tree_arr3($a, $id)
{
    $tree = array();                                //每次都声明一个新数组用来放子元素
    foreach ($a as $v) {
        if ($v['pid'] == $id) {                      //匹配子记录
            $v['children'] = get_tree_arr3($a, $v['id']); //递归获取子记录
            if ($v['children'] == null) {
                unset($v['children']);             //如果子元素为空则unset()进行删除，说明已经到该分支的最后一个元素了（可选）
            }
            $tree[] = $v;                           //将记录存入新数组
        }
    }
    return $tree;                                  //返回新数组
}

/**
 * 手机号格式检查
 * @param string $mobile
 * @return bool
 */
function check_mobile_number($mobile)
{
    if (!is_numeric($mobile)) {
        return false;
    }
    $reg = '#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#';

    return preg_match($reg, $mobile) ? true : false;
}

//获取客户端真实IP
function getClientIP()
{
    global $ip;
    if (getenv("HTTP_CLIENT_IP")) {
        $ip = getenv("HTTP_CLIENT_IP");
    } else if (getenv("HTTP_X_FORWARDED_FOR")) {
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    } else if (getenv("REMOTE_ADDR")) {
        $ip = getenv("REMOTE_ADDR");
    } else {
        $ip = "Unknow";
    }

    return $ip;
}

/**
 * 获取 IP  地理位置
 * 淘宝IP接口
 * @Return: array
 */
function getCity($ip = '')
{
    if ($ip == '') {
        $url = "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json";
        $ip = json_decode(file_get_contents($url), true);
        $data = $ip;
    } else {
        $url = "http://ip.taobao.com/service/getIpInfo.php?ip=" . $ip;
        $ip = json_decode(file_get_contents($url));
        if ((string)$ip->code == '1') {
            return false;
        }
        $data = (array)$ip->data;
    }

    return $data;
}

/**
 * 切分SQL文件成多个可以单独执行的sql语句
 * @param $file sql文件路径
 * @param $tablePre 表前缀
 * @param string $charset 字符集
 * @param string $defaultTablePre 默认表前缀
 * @param string $defaultCharset 默认字符集
 * @return array
 */
function lotus_split_sql($file, $tablePre, $charset = 'utf8mb4', $defaultTablePre = 'lotus_', $defaultCharset = 'utf8mb4')
{
    if (file_exists($file)) {
        //读取SQL文件
        $sql = file_get_contents($file);
        $sql = str_replace("\r", "\n", $sql);
        $sql = str_replace("BEGIN;\n", '', $sql);//兼容 navicat 导出的 insert 语句
        $sql = str_replace("COMMIT;\n", '', $sql);//兼容 navicat 导出的 insert 语句
        $sql = str_replace($defaultCharset, $charset, $sql);
        $sql = trim($sql);
        //替换表前缀
        $sql = str_replace(" `{$defaultTablePre}", " `{$tablePre}", $sql);
        $sqls = explode(";\n", $sql);
        return $sqls;
    }

    return [];
}

/**
 * 随机字符串生成
 * @param int $len 生成的字符串长度
 * @return string
 */
function lotus_random_string($len = 6)
{
    $chars = [
        "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k",
        "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v",
        "w", "x", "y", "z", "A", "B", "C", "D", "E", "F", "G",
        "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
        "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2",
        "3", "4", "5", "6", "7", "8", "9"
    ];
    $charsLen = count($chars) - 1;
    shuffle($chars);    // 将数组打乱
    $output = "";
    for ($i = 0; $i < $len; $i++) {
        $output .= $chars[mt_rand(0, $charsLen)];
    }
    return $output;
}

/**
 * 获取网站根目录
 * @return string 网站根目录
 */
function lotus_get_root()
{
    $request = \think\Request::instance();
    $root = $request->root();
    $root = str_replace('/index.php', '', $root);
    if (defined('APP_NAMESPACE') && APP_NAMESPACE == 'api') {
        $root = preg_replace('/\/api$/', '', $root);
        $root = rtrim($root, '/');
    }

    return $root;
}

/**
 * 设置系统配置，通用
 * @param string $key 配置键值,都小写
 * @param array $data 配置值，数组
 * @param bool $replace 是否完全替换
 * @return bool 是否成功
 */
function lotus_set_option($key, $data, $replace = false)
{
    if (!is_array($data) || empty($data) || !is_string($key) || empty($key)) {
        return false;
    }

    $key = strtolower($key);
    $option = [];
    $findOption = \think\Db::name('option')->where('option_name', $key)->find();
    if ($findOption) {
        if (!$replace) {
            $oldOptionValue = json_decode($findOption['option_value'], true);
            if (!empty($oldOptionValue)) {
                $data = array_merge($oldOptionValue, $data);
            }
        }

        $option['option_value'] = json_encode($data);
        \think\Db::name('option')->where('option_name', $key)->update($option);
        \think\Db::name('option')->getLastSql();
    } else {
        $option['option_name'] = $key;
        $option['option_value'] = json_encode($data);
        \think\Db::name('option')->insert($option);
    }
    cache('cmf_options_' . $key, null);//删除缓存
    return true;
}

/**
 * 格式化字节大小
 *
 * @param number $size 字节数
 * @param string $delimiter 数字和单位分隔符
 * @return string            格式化后的带单位的大小
 */
function format_bytes($size, $delimiter = '')
{
    $units = array('B', 'KB', 'MB', 'GB', 'TB', 'PB');
    for ($i = 0; $size >= 1024 && $i < 5; $i++) {
        $size /= 1024;
    }
    return cutNum($size, 2) . $delimiter . $units[$i];
}

//异常字符串处理
function checkStr($str)
{
    switch ($str) {
        case strspn($str, '&#;') > 0:
            $str = ltrim($str, '&#');
            $str = rtrim($str, ';');
            return $str;
        default:
            return $str;
            break;
    }
}


/*********************************** 自建函数 *************************************************/
function p($arr = [])
{
    echo "<pre>";
    print_r($arr);
    echo "<pre>";
}

function d($arr = [])
{
    p($arr);
    die;
}

/**
 * 检测数组,是否为不为空的数组
 * 是 true 否 false
 * @param $arr
 * @return bool
 */
function checkArr($arr)
{
    $res = is_array($arr) ? count($arr) > 0 ? true : false : false;
    return $res;
}

/**
 * 检测是否非空字符串
 * 是 true 否 false
 * @param $str
 * @return bool
 */
function checkString($str = '')
{
    if ($str == '') {
        return false;
    }
    $str = trim($str);
    $res = isset($str) ? empty($str) ? false : true : false;
    return $res;
}

function arrayCombine($arr = [], $id = '')
{
    $temp_key = array_column($arr, $id);  //键值 php5.5+
    $mobile_arr = array_combine($temp_key, $arr);
    return $mobile_arr;
}

/**
 * 获取$_SERVER
 * @param string $param
 * @return mixed|string
 */
function server($param = '')
{
    $request = \think\Request::instance();
    if (!empty($param)) {
        return $request->server($param);
    } else {
        return $request->server();
    }
}

/**
 * 获取$_GET值
 * @param string $param
 * @return mixed|string
 */
function get($param = '')
{
    $request = \think\Request::instance();
    if (!empty($param)) {
        return $request->get($param);
    } else {
        return $request->get();
    }
}

/**
 * 获取$_POST值
 * @param string $param
 * @return mixed|string
 */
function post($param = '')
{
    $request = \think\Request::instance();
    if (!empty($param)) {
        return $request->post($param);
    } else {
        return $request->post();
    }
}

/**
 * 获取$_SESSION值
 * @param string $param
 * @return mixed|string
 */
function getSession($param = '')
{
    $request = \think\Request::instance();
    if (!empty($param)) {
        return $request->session($param);
    } else {
        return $request->session();
    }
}

/**
 * @param string $param
 * @return int
 * 格式化参数 int
 */
function ipost($param = '')
{
    return (int)post($param);
}

function spost($param = '')
{
    return (string)trim(post($param));
}

function iget($param = '')
{
    return (int)get($param);
}

function sget($param = '')
{
    return (string)trim(get($param));
}

function isession($param = '')
{
    return (int)getSession($param);
}

function ssession($param = '')
{
    return (string)trim(getSession($param));
}

/**
 * 生成php随机数
 * @param $length
 * @return string
 */
function randomsku($length)
{
    $key = '';
    $pattern = '1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLOMNOPQRSTUVWXYZ';
    for ($i = 0; $i < $length; $i++) {
        $key .= $pattern{mt_rand(0, 35)};
    }
    return $key;
}

function randomkeys($length)
{
    $str = null;
    $strPol = "1234567890";//大小写字母以及数字
    $max = strlen($strPol) - 1;

    for ($i = 0; $i < $length; $i++) {
        $str .= $strPol[rand(0, $max)];
    }
    return $str;
}

/**
 * 确保文件夹存在并可写
 * @param $dir  绝对路径$_SERVER['DOCUMENT_ROOT']
 */
function ensure_writable_dir($dir)
{
    if (!is_dir($dir)) {
        mkdir($dir . '/', 0777, true);
    }
}

/**
 * 更新所有换行符为指定符号
 * @param string $str
 * @param string $spliter
 * @return mixed|string|string[]|null
 */
function transitionbr($str = '', $spliter = '')
{
    $str = trim($str);
    if ($str == '') {
        return '';
    }
    $br = '<br/>';
    empty($spliter) && $spliter = "\r\n";

    if (strpos($str, '\n') !== false && strpos($str, '\r') === false) {//不存在\r存在\n
        $str = str_replace("\n", $br, $str);
    }
    if (strpos($str, '\r') !== false && strpos($str, '\n') === false) {//不存在\n存在\r
        $str = str_replace("\r", $br, $str);
    }
    if (strpos($str, CHR(10)) !== false) {
        $str = str_replace(CHR(10), $br, $str);
    }
    if (strpos($str, CHR(13)) !== false) {
        $str = str_replace(CHR(13), $br, $str);
    }
    if (strpos($str, '\r\n') !== false) {//存在\r\n
        $str = str_replace("\r\n", $br, $str);
    }
    if (strpos($str, '<br/>') !== false) {//存在<br/>
        $str = preg_replace('/<br\/>\s*/', $br, $str);
        $str = preg_replace('/(<br\/>)+/i', $spliter, $str);
    }
    return $str;
}

/**
 * 微秒组装字符串
 * @return string
 */
function getNumString()
{
    $time = microtime(true);
    $times = explode('.', $time);
    return $times[1] . $times[0];
}

/**
 * GUID的生成源码
 * *代码中//后面标示了字符的转码如chr(45)代表“-”，chr(123)代表“{”等等，可以根据自己需要改写生成GUID的位数以及样式
 * @return string   26E69265-078C-C7D9-A0CA-33348CEEE712
 */

function guid()
{
    if (function_exists('com_create_guid')) {
        return com_create_guid();
    } else {
        mt_srand((double)microtime() * 10000);//optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = substr($charid, 0, 8) . $hyphen
            . substr($charid, 8, 4) . $hyphen
            . substr($charid, 12, 4) . $hyphen
            . substr($charid, 16, 4) . $hyphen
            . substr($charid, 20, 12);
        return strtolower($uuid);
    }
}

/**
 * 创建guid
 * 927D69607CC9DF2160B1
 * @return string
 */
function create_guid()
{
    $charid = strtoupper(md5(uniqid(mt_rand(), true)));
    $uuid = substr($charid, 0, 8)
        . substr($charid, 8, 4)
        . substr($charid, 12, 4)
        . substr($charid, 16, 4);
    return strtolower($uuid);
}

/**
 * 模拟post进行url请求
 * @param string $url
 * @param string $curlPost
 * @param array $header
 * @return bool|string
 */
function request_post($url = '', $curlPost = '', $header = [])
{
    if (empty($url) || empty($curlPost)) {
        return false;
    }

    $header = count($header) > 0 ? $header : array("Content-type: text/xml");
    $ch = curl_init();//初始化curl
    curl_setopt($ch, CURLOPT_URL, $url);//抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
    $data = curl_exec($ch);//运行curl
    curl_close($ch);

    return $data;
}

/**
 * 模拟post进行url请求
 * @param string $url
 * @param array $post_data
 * @param array $header
 * @return bool|string
 */
function request_post2($url = '', $post_data = array(), $header = [])
{
    if (empty($url) || empty($post_data)) {
        return false;
    }

    $o = "";
    foreach ($post_data as $k => $v) {
        $o .= "$k=" . urlencode($v) . "&";
    }
    $post_data = substr($o, 0, -1);

    $postUrl = $url;
    $header = count($header) > 0 ? $header : array("Content-type: text/xml");
    $ch = curl_init();//初始化curl
    curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页
    curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
    curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    $data = curl_exec($ch);//运行curl
    curl_close($ch);

    return $data;
}

/**
 * 模拟get进行url请求
 * @param string $url
 * @param array $header
 * @return bool|string
 */
function request_get($url = '', $header = [])
{
    $ch = curl_init();
    $header = count($header) > 0 ? $header : array("Content-type: text/xml");
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 15);
    curl_setopt($ch, CURLOPT_POST, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $response = curl_exec($ch);
    return $response;
}

/**
 * 下载远程图片
 */
function downloadImgUrl($url, $path)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    $file = curl_exec($ch);
    curl_close($ch);
    $resource = fopen($path, 'a');
    fwrite($resource, $file);
    fclose($resource);
}
/**
 * 将XML转为array
 * @param $xml
 * @return mixed
 */
function xmlToArray($xml)
{
    //禁止引用外部xml实体
    libxml_disable_entity_loader(true);
    $values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
    return $values;
}

/**
 * GMT 标准日期转换时间戳
 * @param $date
 * @return false|int
 */
function gmtToUtc($date)
{
    return strtotime($date) + 28800;
}

/**
 * 数字转字母 （类似于Excel列标）
 * @param Int $index 索引值
 * @param Int $start 字母起始值
 * @return String 返回字母
 */
function IntToChr($index, $start = 65)
{
    $str = '';
    if (floor($index / 26) > 0) {
        $str .= IntToChr(floor($index / 26) - 1);
    }
    return $str . chr($index % 26 + $start);
}

/**
 * 处理字符串中多个连续br替换一个
 * @param string $str
 * @return string
 */
function handContent($str = '')
{
    $arr = array_filter(explode("<br/>", $str));
    return implode("<br/>", $arr);
}

/**
 * 硬盘B转换
 * @param int $num
 * @return string
 */
function diskTransform($num = 0)
{
    if ($num < 1024) {
        return $num . 'B';
    }
    $num = $num / 1024;
    if ($num < 1024) {
        return cutNum($num, 2) . 'KB';
    }
    $num = $num / 1024;
    if ($num < 1024) {
        return cutNum($num, 2) . 'MB';
    }
    $num = $num / 1024;
    if ($num < 1024) {
        return cutNum($num, 2) . 'GB';
    }

    $num = $num / 1024;
    if ($num < 1024) {
        return cutNum($num, 2) . 'TB';
    }

    $num = $num / 1024;
    return cutNum($num, 2) . 'PB';

}

/**
 * 准确的保留数字最后小数
 */
function cutNum($number, $num)
{
    return round($number, $num);
}

/**
 * 硬盘使用百分比
 * @param int $total GB
 * @param int $use B
 * @return float|int
 */
function getDiskBar($total = 0, $use = 0)
{

    if ($total == 0 || $use == 0) {
        return 0;
    }
    $bar = $use / $total / 1024 / 1024 / 1024 * 100;
    return cutNum($bar, 2) . '%';
}

/**
 * 检测是否总公司管理员
 * 是 true 否false
 * @return bool
 */
function checkHeadOfficeManage()
{
    if ((isession('super') == 2) && (isession('pid') == 1) && (isession('company_id') == 0) && (isession('type') == 1)) {
        return true;
    }
    return false;
}


/**
 * 列表总管理员入口检测跳转
 * 需要跳转 true 不需要跳转 false
 * @return bool
 */
function checkEntranceList()
{
    if (checkHeadOfficeManage() && !isset($_GET['company_id'])) {
        return true;
    }
    return false;
}

/**
 * 检测总管理员添加页面权限
 * 无权访问 true 有权访问 false
 * @return bool
 */
function checkEntranceAdd()
{
    $data = get();
    if (checkHeadOfficeManage() && ($data['company_id'] != isession('company_id')) && (!empty($data['company_id']))) {
        return true;
    }
    return false;
}

/**
 * 检测总管理员是否有提交编辑数据权限
 * 无权提交 true 有权提交 false
 * @return bool
 */
function checkSubmitEdit()
{
    $data = post();
    if (checkHeadOfficeManage() && isset($data['company_id']) && ($data['company_id'] != isession('company_id')) && (!empty($data['company_id']))) {
        return true;
    }
    return false;
}

/**
 * 检测是否是管理员,总管理，子管理
 * 是 true    否 false
 * @return bool
 */
function checkAdministrator()
{
    //总管理
    if (checkHeadOfficeManage()) {
        return true;
    }
    //子管理员
    if ((isession('super') == 3) && (isession('type') == 2)) {
        return true;
    }
    return false;
}

/**
 * 检测容量是否超标
 * true 空间足够    false 空间不足
 * @param array $company
 * @param int $num
 * @return bool
 */
function checkDiskSpace($company = [], $num = 0)
{
    if ($num == 0) {
        return true;
    }
    $upload_capacity = $company['upload_capacity'] * 1024 * 1024 * 1024;
    $res = $upload_capacity - $company['use_capacity'] - $num;
    return ($res > 0) ? true : false;
}

/**
 * 比较空间大小
 * @param int $upload_capacity 单位GB
 * @param int $use_capacity 单位B
 * @param int $num 单位B
 * @return bool
 */
function compareDiskSpace($upload_capacity = 0, $use_capacity = 0, $num = 0)
{
    if ($num == 0) {
        return true;
    }
    $upload_capacity = $upload_capacity * 1024 * 1024 * 1024;
    $res = $upload_capacity - $use_capacity - $num;
    return ($res > 0) ? true : false;
}


/**
 * 写日志
 */
function wlog($content)
{
    //写入日志
    $file = server("DOCUMENT_ROOT") . "/runtime/log.log";
    file_put_contents($file, "\r\n********************** " . date('Y-m-d H:i:s', time()) . " **********************************\r\n", FILE_APPEND);
    file_put_contents($file, $content, FILE_APPEND);
}
